package net.oschina.app.adapter.center_message;

import android.graphics.drawable.Drawable;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.Html;
import android.text.Spanned;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import net.oschina.app.R;
import net.oschina.app.base.BaseAdapter;
import net.oschina.app.bean.ActiveBean;
import net.oschina.app.util.CommonUtils;

import org.xml.sax.XMLReader;

import butterknife.BindView;
import butterknife.ButterKnife;
import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by zuo on 2017/1/14.
 * 我---消息界面的@我界面
 */

public class AtMeAdapter extends BaseAdapter {
    @Override
    public AtMeAdapter.AtMeHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemtView = CommonUtils.getInflate().inflate(R.layout.item_centermessage_atme, parent, false);
        AtMeAdapter.AtMeHolder newsInfosHolder = new AtMeAdapter.AtMeHolder(itemtView);
        return newsInfosHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ActiveBean activeBean = (ActiveBean) mDatas.get(position);
        AtMeHolder atMeHolder = (AtMeHolder) holder;
        Glide.with(CommonUtils.getContext()).load(activeBean.getPortrait()).into(atMeHolder.mCiPic);
        atMeHolder.mTvName.setText(activeBean.getAuthor());
        String message = activeBean.getMessage();
        //富文本的显示
        Spanned html = Html.fromHtml(message, new Html.ImageGetter() {
            @Override
            public Drawable getDrawable(String source) {
                return null;
            }
        }, new Html.TagHandler() {
            @Override
            public void handleTag(boolean opening, String tag, Editable output, XMLReader xmlReader) {

            }
        });
        atMeHolder.mDesc.setText(html);
    }

    static class AtMeHolder extends RecyclerView.ViewHolder{
        @BindView(R.id.ci_pic)
        CircleImageView mCiPic;
        @BindView(R.id.tv_name)
        TextView mTvName;
        @BindView(R.id.tv_update)
        TextView mTvUpdate;
        @BindView(R.id.desc)
        TextView mDesc;


        AtMeHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
